package com.gxa.employment.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.employment.entity.pojo.Major;
import com.gxa.employment.entity.vo.AvgAndRateVo;
import com.gxa.employment.entity.vo.AvgSalaryWithYearVo;
import com.gxa.employment.entity.vo.MajorSalaryVo;
import com.gxa.employment.entity.vo.MajorStatisticsVo;
import com.gxa.employment.exception.BizException;
import com.gxa.employment.exception.ErrorMessage;
import com.gxa.employment.mapper.MajorMapper;
import com.gxa.employment.service.MajorService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 方向管理表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-03-25
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class MajorServiceImpl extends ServiceImpl<MajorMapper, Major> implements MajorService {
@Autowired
private MajorMapper majorMapper;

    @Override
    public MajorStatisticsVo getMajorStatistics(String year) throws BizException {
        Integer yearNum;
        try{
            yearNum = Integer.parseInt(year);
        }catch (Exception e){
            throw new BizException(ErrorMessage.ERROR_FORMAT);
        }
        //4.1.	就业信息统计  的各个方向的统计结果
        //平均薪资
        List<AvgAndRateVo> majorAvgSalaryList = majorMapper.selectMajorAvgSalary(yearNum);
        //就业率
        List<AvgAndRateVo> employmentRateList = majorMapper.selectEmploymentRate(yearNum);
        //新增分布情况
        List<MajorSalaryVo> majorSalaryList = majorMapper.selectAllSalary(yearNum);
        //入职时间的新增情况
        List<AvgSalaryWithYearVo> avgSalaryList = majorMapper.selectAvgSalary(yearNum);

        return new MajorStatisticsVo(majorAvgSalaryList,employmentRateList,majorSalaryList,avgSalaryList);
    }
}
